package jielong

import (
	"strconv"
	"youdu/common"
	daoListUsers "youdu/dao/jielong/list_users"
	"youdu/mock"
	modelJielong "youdu/model/jielong"

	"github.com/brianvoe/gofakeit/v6"
	"github.com/gin-gonic/gin"
)

func ListUserAdd(c *gin.Context) {
	id := c.Param("id")
	if id == "" {
		common.ResFail(c, "id不能为空")
		return
	}
	lid, err := strconv.ParseUint(id, 10, 32)
	if err != nil {
		common.ResFail(c, "id必须为数字")
		return
	}
	// 初始化 faker
	gofakeit.Seed(0)
	user := modelJielong.ListUsers{
		ListID:      uint(lid),
		Content:     "同意参加活动",
		UserName:    mock.MakeChineseName(),
		UserAccount: gofakeit.Username(),
	}
	if err := daoListUsers.Add(&user); err != nil {
		common.ResFail(c, err.Error())
		return
	}
	common.ResSuccess(c, user.ID)
}
